﻿using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Models;

public partial class NewList : AdminBase
{
    public int classId;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ClassTreeBind("请选择栏目...", this.Classddl);

            if (!string.IsNullOrEmpty(Request.Params["CID"]))
            {
                string _CId = HttpContext.Current.Request.QueryString["CID"];
                Classddl.SelectedValue = _CId;

               
            }

            myDatabind();


        }
    }


    private void myDatabind()
    {

        if (!int.TryParse(this.Classddl.SelectedValue as string, out this.classId))
        {
            this.classId = 0;
        }

        //if (classId != 0)
        //{
        using (Entities bll = new Entities())
        {

            var Bpl = bll.TRS_newss.Select(s => new
            {
                NId = s.DOCID,
                ClassId = s.DOCCHANNEL,
                Title = s.DOCTITLE,
                Time = s.DOCRELTIME,
                From=s.OPERUSER,
                status = s.DOCSTATUS,
                DOCKIND=s.DOCKIND,
            }).Where(x=>x.DOCKIND==-1);



            //if (txtkey.Text.Trim() != "")
            //{
            //    Bpl = Bpl.Where(p => p.Title.Contains(txtkey.Text));
            //}


         


            if (this.classId > 0)
            {
                Bpl = Bpl.Where(p => p.ClassId == classId);
            }
           

           Bpl = Bpl.OrderByDescending(p => p.Time);


            PagedDataSource pds = new PagedDataSource();
            pds.DataSource = Bpl.ToList();  //这里好像一定要Tolist();不然会有点错误；
            pds.AllowPaging = true;
            AspNetPager1.RecordCount = Bpl.Count(); //记录总数；
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            pds.PageSize = AspNetPager1.PageSize;

            this.rptList.DataSource = pds;
            this.rptList.DataBind();
        }
        //}

    }


  




    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {   //当页面页数改变时，执行这个方法；
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        myDatabind();
    }
    protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int id = Convert.ToInt32(e.CommandArgument);


        Entities bll = new Entities();
        TRS_newss model = bll.TRS_newss.First(p => p.DOCID == id);

        switch (e.CommandName.ToLower())
        {
         

            case "huifu":

                model.DOCKIND = 0;
                bll.SaveChanges();
                break;

        }

        bll.SaveChanges();
        myDatabind();
        //RptBind("Id>0" + CombSqlTxt(this.kindId, this.classId, this.keywords, this.property), "AddTime desc");
    }

    public string ToClassName(int ClassId)
    {
        string result = "";
        Entities db = new Entities();
        var LClass = db.L_Classs.SingleOrDefault(p => p.CID == ClassId);
        result = LClass.CNmae;
        return result;
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        myDatabind();
    }

    protected void ddlProperty_SelectedIndexChanged(object sender, EventArgs e)
    {
        myDatabind();
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        myDatabind();
    }


  
}

